import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.sql.Date;
import java.util.Calendar;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.JDialog;

public class MedicFile {

	// Global variables


	public MedicFile() {

		
		
		// while (threadSend.isAlive() && threadServer.isAlive()) {}
	}

	public static void main(String[] args) {

		// ---------------------------------------------------
		// System tray test DO NOT REMOVE
		MyTrayIcon.displayTray();

		// ---------------------------------------------------
		// Preferences Properties test DO NOT REMOVE
		PrefProperties.getPreferences();
		
		if ( PrefProperties.lastSave == null ){
			System.out.println("Here");
		}
		
		// ---------------------------------------------------
		// Preferences Properties test HAS TO be removed
		//PrefProperties.isFirtTime = true;
		//MyTrayIcon.enableMenu();

		// ---------------------------------------------------
		// GUI test
		//
		if ((PrefProperties.isFirtTime != null && PrefProperties.isFirtTime == true) 
				|| PrefProperties.isFirtTime == null) {
			try {
				
				GUIWelcomeDialog dialog = new GUIWelcomeDialog();
				dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
				dialog.setVisible(true);
				
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		else {
			
			MyTrayIcon.enableMenu();
			
			PrefProperties.launchRoutine();
			PrefProperties1.launchRoutine();
			PrefProperties2.launchRoutine();
			PrefProperties3.launchRoutine();
		}

		// ---------------------------------------------------
		// Serialization test
//		FileObject toSerializeFile = new FileObject(
//				"MedicFile-Tests/H_2A3D4RFQ/FEC.odt");
//		File serializedFile = FileOperation.serializeFile(toSerializeFile);
//		File serializedAndEncryptedFile = FileOperation.encrytpFile(
//				serializedFile, PrefProperties.password);

		// ---------------------------------------------------
		// Move file to "to-send" directory
//		try {
//
//			if (serializedAndEncryptedFile.renameTo(new File(
//					"MedicFile-Tests/.to-send/"
//							+ serializedAndEncryptedFile.getName()))) {
//
//			} else {
//				System.out.println("File is failed to move!");
//			}
//
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//
//		File toDecryptFile = new File(
//				"MedicFile-Tests/.to-send/FEC-serialized.crp");
//		File toUnserializeFile = FileOperation.decryptFile(toDecryptFile,
//				PrefProperties.password);
//		FileObject recoveredFile = FileOperation
//				.unserializeFile(toUnserializeFile);
//		recoveredFile.writeFile(recoveredFile.dir + "/OK-"
//				+ recoveredFile.fileName);

		// ---------------------------------------------------
		// Preferences Properties test
		// PrefProperties.savePreferences();

		// ---------------------------------------------------
		// Thread test
		new MedicFile();
	}
	
	

}
